<template>
<view>
  <tn-nav-bar alpha customBack :isBack="false">
    <!-- 搜索框 -->
    <view class="custom-nav__search tn-flex tn-flex-col-center tn-flex-row-center">
      <view v-if="searchBar.enable" :class="{'skeleton': skeleton}" class="custom-nav__search__box tn-flex tn-flex-col-center tn-flex-row-left" style="background-color: rgba(255,255,255,0.7);">
        <view class="custom-nav__search__icon tn-icon-search tn-color-gray"></view>
        <tn-input disabled :placeholder="searchBar.placeholder" class="custom-nav__search__text tn-padding-left-xs tn-color-gray" />
      </view>
    </view>
  </tn-nav-bar>
	<view class="container" :style="{paddingTop: vuex_custom_bar_height + 'px'}">
    <!-- 头部轮播 -->
    <view class="carousel-section" :class="{'skeleton': skeleton}">
      <swiper class="carousel" :indicator-dots="true" :duration="swiper.duration || 300" :interval="swiper.interval || 3000" autoplay circular>
        <swiper-item v-for="(item, index) in swiper.items" :key="index" class="carousel-item">
          <e-image :url="item.url" />
        </swiper-item>
      </swiper>
    </view>

    <!-- 分类 -->
    <view class="cate-section" :class="{'skeleton': skeleton}">
      <view class="cate-item" v-for="nav in navs" :key="nav.id">
        <e-image :url="nav.icon"></e-image>
        <text>{{ nav.title }}</text>
      </view>
    </view>
    <tn-notice-bar
      :show="noticeBar.enable && !skeleton"
      :list="noticeBar.list"
      :speed="noticeBar.speed"
      :circular="noticeBar.circular"
      :font-color="noticeBar.fontColor"
      :background-color="noticeBar.backgroundColor"
      :class="{'skeleton': skeleton}">
    </tn-notice-bar>
    <!-- #ifdef MP-WEIXIN -->
    <view class="tn-text-center" style="margin-top: 20rpx;" v-if="!skeleton && !location">
      <view class="tn-text-ellipsis">请授权获取您的位置信息，以便提供更精准服务</view>
      <view class="tn-icon-set" style="color: #1D2541"  @click="openSetting">点击授权</view>
    </view>
    <!-- #endif -->

		<view class="list">
			<view class="item" :class="{'skeleton': skeleton}" v-for="(item,index) in list" :key="index">
				<view class="iTop">
					<image src="https://salephine.asia/img/index/logoo.gif" class="shopImg" mode=""></image>
					<view class="itRight">
						<view class="shopName">
							{{item.name}}
						</view>
					</view>
				</view>
				<view class="center">
					<image
						:src="item.img"
						mode=""></image>
				</view>
				<view class="title">
					{{item.title}}
				</view>
				<view class="bottom">
					<view class="bl">
						<view class="tt">
							{{item.tip}}
						</view>
					</view>
					<view class="price">
						￥{{item.price}}
					</view>
				</view>
			</view>
		</view>
	</view>
</view>
</template>

<script>

  import { fetchCarousel } from "@/api/sem/carousel";
  import { navList } from '@/api/app/home-nav'
  import EImage from "@/components/e-image.vue";
  import {getConfigs} from "../../api/app/home-config";

  export default {
    components: { EImage},
		data() {
			return {
        skeleton: true,
		    latitude: 100,
        searchBar: {
          enable: true,
          placeholder: '搜索商品'
        },
				list:[
					{name:'小周女士',header:'https://salephine.asia/img/index/logoo.gif',title:'高腰遮胯牛仔短裙女夏2023新款蓝色a字显瘦防走光小个子半身裙子',tip:'1030人想要',price:'325.99',img:'https://g-search1.alicdn.com/img/bao/uploaded/i4/imgextra/i4/53810478/O1CN01cbw7jj1FOy9YfCy29_!!0-saturn_solar.jpg_250x250.jpg_.webp'},
					{name:'小吴女士',header:'https://salephine.asia/img/index/logoo.gif',title:'高腰遮胯牛仔短裙女夏2023新款蓝色a字显瘦防走光小个子半身裙子',tip:'1030人想要',price:'335.99',img:'https://g-search1.alicdn.com/img/bao/uploaded/i4/i2/3596248858/O1CN01V2YinW2FJ179lJLas_!!0-item_pic.jpg_250x250.jpg_.webp'},
					{name:'小王女士',header:'https://salephine.asia/img/index/logoo.gif',title:'高腰遮胯牛仔短裙女夏2023新款蓝色a字显瘦防走光小个子半身裙子',tip:'1030人想要',price:'345.99',img:'https://g-search1.alicdn.com/img/bao/uploaded/i4/imgextra/i4/53810478/O1CN01cbw7jj1FOy9YfCy29_!!0-saturn_solar.jpg_250x250.jpg_.webp'},
					{name:'小李女士',header:'https://salephine.asia/img/index/logoo.gif',title:'高腰遮胯牛仔短裙女夏2023新款蓝色a字显瘦防走光小个子半身裙子',tip:'1030人想要',price:'355.99',img:'https://g-search1.alicdn.com/img/bao/uploaded/i4/i2/3596248858/O1CN01V2YinW2FJ179lJLas_!!0-item_pic.jpg_250x250.jpg_.webp'},
					{name:'小张女士',header:'https://salephine.asia/img/index/logoo.gif',title:'高腰遮胯牛仔短裙女夏2023新款蓝色a字显瘦防走光小个子半身裙子',tip:'1030人想要',price:'365.99',img:'https://g-search1.alicdn.com/img/bao/uploaded/i4/imgextra/i4/53810478/O1CN01cbw7jj1FOy9YfCy29_!!0-saturn_solar.jpg_250x250.jpg_.webp'},
					{name:'小刘女士',header:'https://salephine.asia/img/index/logoo.gif',title:'高腰遮胯牛仔短裙女夏2023新款蓝色a字显瘦防走光小个子半身裙子',tip:'1030人想要',price:'375.99',img:'https://g-search1.alicdn.com/img/bao/uploaded/i4/imgextra/i4/53810478/O1CN01cbw7jj1FOy9YfCy29_!!0-saturn_solar.jpg_250x250.jpg_.webp'},
					{name:'小郑女士',header:'https://salephine.asia/img/index/logoo.gif',title:'高腰遮胯牛仔短裙女夏2023新款蓝色a字显瘦防走光小个子半身裙子',tip:'1030人想要',price:'385.99',img:'https://g-search1.alicdn.com/img/bao/uploaded/i4/i2/3596248858/O1CN01V2YinW2FJ179lJLas_!!0-item_pic.jpg_250x250.jpg_.webp'},
					{name:'小美女士',header:'https://salephine.asia/img/index/logoo.gif',title:'高腰遮胯牛仔短裙女夏2023新款蓝色a字显瘦防走光小个子半身裙子',tip:'1030人想要',price:'395.99',img:'https://g-search1.alicdn.com/img/bao/uploaded/i4/imgextra/i4/53810478/O1CN01cbw7jj1FOy9YfCy29_!!0-saturn_solar.jpg_250x250.jpg_.webp'},
					{name:'小瘪三女士',header:'https://salephine.asia/img/index/logoo.gif',title:'高腰遮胯牛仔短裙女夏2023新款蓝色a字显瘦防走光小个子半身裙子',tip:'1030人想要',price:'355.99',img:'https://g-search1.alicdn.com/img/bao/uploaded/i4/i2/3596248858/O1CN01V2YinW2FJ179lJLas_!!0-item_pic.jpg_250x250.jpg_.webp'},
					{name:'小淘气女士',header:'https://salephine.asia/img/index/logoo.gif',title:'高腰遮胯牛仔短裙女夏2023新款蓝色a字显瘦防走光小个子半身裙子',tip:'1030人想要',price:'985.99',img:'https://g-search1.alicdn.com/img/bao/uploaded/i4/imgextra/i4/53810478/O1CN01cbw7jj1FOy9YfCy29_!!0-saturn_solar.jpg_250x250.jpg_.webp'},
				],
        location: true,
        swiper: {},
        navs: [
          {
            "id": 1,
            "title": "积分购",
            "icon": "2024/08/18/jifen1a0bf6c7-1e31-4824-bc64-ecbd73cb191f.png",
            "route": null,
          },
          {
            "id": 2,
            "title": "二手闲置",
            "icon": "2024/08/18/xianzhiddbd92af-3195-42c2-ab74-19fd2a8ae1a8.png",
            "route": "/home",
          },
          {
            "id": 3,
            "title": "求购",
            "icon": "2024/08/18/求购74b30ddf-9f28-491e-a82f-1e9c7e3c814e.png",
            "route": null,
          },
          {
            "id": 4,
            "title": "租房",
            "icon": "2024/08/18/xianzhi53ebf0f5-665d-4cda-b553-f5ebecfd0e50.png",
            "route": null,
          },
          {
            "id": 5,
            "title": "求租",
            "icon": "2024/08/18/jifen15e60e7e-bb51-43be-9993-305b667f5dd4.png",
            "route": null,
          }
        ],
        noticeBar: []
			}
		},
		onLoad() {
      this.getCarousel()
      this.getNavList()
      this.getHomeConfig()
      setTimeout(() => {
        this.skeleton = false
        // #ifdef MP-WEIXIN
        this.getLocation()
        // #endif
      }, 2000)
		},
		methods: {
      async getCarousel() {
        const { data } = await fetchCarousel('home')
        this.swiper = data
      },
      async getNavList() {
        const { data } = await navList()
        this.navs = data
      },
      async getHomeConfig() {
        const { data } = await getConfigs()
        this.noticeBar = data.noticeBar
        this.searchBar = data.searchBar
      },
      // #ifdef MP-WEIXIN
      openSetting() {
        const _ = this
        uni.openSetting({
          success(res) {
            if (res.authSetting['scope.userLocation']) {
              _.getLocation()
            }
          },
          fail(e) {
            console.log(e)
          }
        });
      },
      getLocation() {
        uni.getLocation({
          success: (e) => {
            this.location = e
            console.log(e)
          },
          fail: (e) => {
            this.location = false
          }
        })
      },
      // #endif
      tn(url) {
        uni.navigateTo({
          url: url
        })
      },
		}
	}
</script>
<style>
	page {
		margin: 0;
		padding: 0;
		height: 100%;
		width: 100%;
	}
	/*去掉页面滚动条*/
	::-webkit-scrollbar {
		display: none !important;
		width: 0 !important;
		height: 0 !important;
		-webkit-appearance: none;
		background: transparent;
	}
</style>
<style lang="scss" scoped>
  /* 自定义导航栏内容 start */
  .custom-nav {
    height: 100%;

    &__search {
      flex-basis: 60%;
      width: 60%;
      height: 100%;

      &__box {
        width: 100%;
        height: 70%;
        padding: 10rpx 0;
        margin: 0 30rpx;
        border-radius: 60rpx 60rpx 0 60rpx;
        font-size: 24rpx;
      }

      &__icon {
        padding-right: 10rpx;
        margin-left: 20rpx;
        font-size: 30rpx;
      }

    }
  }
	.container {
		height: 100%;
		width: 100%;
		font-family: PingFangSC-Semibold, PingFang SC;
		padding: 30rpx 30rpx 60rpx 30rpx;
		box-sizing: border-box;
		color: #333;
		overflow-y: scroll !important;

    /* 头部 轮播图 */
    .carousel-section {
      width: 100%;
      overflow: hidden;
      border-radius: 16rpx;
      background-color: #ebebeb !important;

      .carousel {
        width: 100%;
        height: 350upx;

        .carousel-item {
          width: 100%;
          height: 100%;

          .e-image {
            width: 100%;
            height: 100%;
          }
        }
      }
    }

    /* 分类 */
    .cate-section {
      position: relative;
      display: flex;
      justify-content: space-around;
      align-items: center;
      flex-wrap:wrap;
      margin-top: 30rpx;
      padding: 30upx 22upx;
      background: #fff;
      border-radius: 16rpx;
      .cate-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        font-size: 26upx;
        color: #333;

          /* 原图标颜色太深,不想改图了,所以加了透明度 */
        e-image {
          width: 88upx;
          height: 88upx;
          margin-bottom: 14upx;
          //border-radius: 50%;
          opacity: .7;
          //box-shadow: 4upx 4upx 20upx rgba(250, 67, 106, 0.3);
        }
      }
    }

		.list {
			margin-top: 30rpx;
      display: flex;
      align-items: center;
			justify-content: flex-start;
			flex-wrap: wrap;
			.item {
				width: 48%;
				padding: 10rpx 0 10rpx 0;
				box-sizing: border-box;
				background-color: #fff;
				border-radius: 16rpx;
				margin-bottom: 30rpx;
				&:nth-child(odd) {
					margin-right: 4% !important;
					.badge:nth-child(odd){
						background-color: #f3cf90 !important;
					}
				}
				.iTop {
          display: flex;
          align-items: center;
					justify-content: flex-start;
					padding: 10rpx;
					box-sizing: border-box;
					.shopImg {
						width: 40rpx;
						height: 40rpx;
						border-radius: 50%;
						margin-right: 10rpx;
					}
					.itRight {
            display: flex;
						justify-content: flex-start;
						align-items: flex-start;
						flex-direction: column;
						.shopName {
							color: #333;
							font-size: 24rpx;
							margin-bottom: 4rpx;
						}
						.auth {
							padding: 2rpx 4rpx;
							box-sizing: border-box;
							border: 1rpx solid #bebebe;
							border-radius: 8rpx;
              display: flex;
              align-items: center;
              justify-content: space-between;
							.authIcon {
								width: 24rpx;
								height: 24rpx;
							}
							text {
								font-size: 18rpx;
								color: #bebebe;
							}
						}
					}
				}
			}
			.center {
				width: 100%;
				height: 280rpx;
				background: #f8f8f8;
				margin-top: 12rpx;
				image {
					width: 100%;
					height: 100%;
				}
			}
			.title {
				margin: 20rpx 0rpx 20rpx 10rpx;
				font-size: 24rpx;
				color: #333;
			}
			.bottom {
        display: flex;
        align-items: center;
        justify-content: space-between;
				padding: 4rpx 0rpx 4rpx 10rpx;
				box-sizing: border-box;
				.price {
					color: #f60;
					font-size: 26rpx;
					font-weight: bolder;
					padding: 0rpx 6rpx;
					box-sizing: border-box;
				}
				.bl {
					flex: 1;
          display: flex;
          align-items: center;
					justify-content: flex-start;
					.badge {
						padding: 2rpx 4rpx;
						border-radius: 4rpx;
						box-sizing: border-box;
						color: #fff;
						font-size: 18rpx;
						background-color: #c37b85;
            display: flex;
            justify-content: center;
            align-items: center;
					}
					.tt {
						font-size: 20rpx;
						color: #bebebe;
						margin-left: 4rpx;
					}
				}
			}
		}
	}
</style>
